//
//  SymbolResultFilter.m
//  LinkMap
//
//  Created by aron on 2022/5/7.
//  Copyright © 2022 ND. All rights reserved.
//

#import "SymbolResultFilter.h"
#import "SymbolResultConverter.h"
#import "SymbolUtils.h"

@implementation SymbolResultFilter

- (NSArray *)filterWithSymbols:(NSArray<ObjectResult *> *)symbols filters:(NSArray<NSString *> *)filters {
    if (filters.count == 0) {
        return symbols;
    }
    SymbolResultConverter *converter = [SymbolResultConverter new];
    NSDictionary *symbolMapData = [converter convert2MapData:symbols];
    NSMutableArray *results = [NSMutableArray new];
    for (NSString *filterStr in filters) {
        ObjectResult *obj = symbolMapData[filterStr];
        if (obj) {
            [results addObject:obj];
        }
    }
    return [SymbolUtils sortSymbols:results];
}

@end
